package com.example.mq.kafka.config;

import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.common.Cluster;

import java.util.Map;

/**
 * @author luowenjie
 * @since 2024/4/9 16:39
 */
public class CustomPartitioner implements Partitioner {

    @Override
    public int partition(String topic, Object key, byte[] keyBytes, Object value, byte[] valueBytes, Cluster cluster) {
        // Your partitioning logic here
        // For example, you can hash the key or implement any custom logic to determine the partition
        // Return the partition number
        return 9;
    }

    @Override
    public void close() {
        // Perform any cleanup here
    }

    @Override
    public void configure(Map<String, ?> configs) {
        // Perform any configuration here
    }
}
